In this demo, you
will learn about cascading style sheets or CSS in JavaScript or JS styles using the style
components package. You have previously used regular CSS styles and imported them into
your component files. You have ensured
that the styles are applied where you want
them to be applied. But in larger projects with a large group of developers
working on the code, the name could be used twice. For avoiding repetition, one method is to use a package
called styled components. Go to the official website,
styled components. A CSS and JS tool
is a package that helps you build
components that have certain styles attached to them, where the styles affect only the components to
which they are attached, and not the other components. First, install the styled
components package. Go to the created boilerplate, and in the root directory, either run Node Package
Manager or NPM install hyphen, hyphen, save, style
hyphen components. Go to the login component and use the style
components package. First, import the package
dialed components. Add the style component
styled button, and it will be rendered as
a hypertext markup language or HTML button with
the contained styles. Styled is an internal
utility method that transforms the styling from JavaScript into the actual CSS. The HTML button
here is a method on the style object which you are importing from the
style components. The style components package has methods for all
the HTML elements. It has a p method
for a paragraph, H1, H2, and so on. So the styled.button
returns a button with styles provided in
between the back ticks. Add the styles to the button, run the application now. In the output, the login
button has the styles applied. Open the developer tools to
check the regular button. But there are two
strange classes that you did not set up. These are class
names dynamically generated by the style
components package, which looks at the
styles you set up, and wraps these styles into generated class names were the packaged guarantees that
every class name is unique. The package then adds these
classes as global CSS. This is how the style
components package works. Thank you.